package com.tjhk.test.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjhk.test.entity.CheckData;
import com.tjhk.test.mapper.CheckDataMapper;
import com.tjhk.test.service.CheckDataService;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：little grape
 * @description：TODO
 * @date ：2022/12/10 17:41
 */
@Service
public class CheckDataServiceImpl extends ServiceImpl<CheckDataMapper, CheckData> implements CheckDataService {
    @Override
    public boolean saveExcelValues(String[][] excelValues) {
        try {
            List<CheckData> list = new ArrayList<>();
            DecimalFormat df = new DecimalFormat("#.###");
            for (int i = 0; i < excelValues.length; i++) {
                CheckData checkData = new CheckData();
                int j = 0;
                checkData.setSiteName(excelValues[i][j++]);
                checkData.setCollectTime(excelValues[i][j++]);
                checkData.setSo2(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setNo2(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setPm10(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setPm25(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setCo(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setO3(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setNo(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setNox(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setAqi(df.format(Double.parseDouble(excelValues[i][j++])));
                checkData.setAqiLevel(excelValues[i][j++]);
                checkData.setPp(excelValues[i][j++]);
                checkData.setAtmosphere(excelValues[i][j++]);
                checkData.setTemperature(excelValues[i][j++]);
                checkData.setHumidity(excelValues[i][j++]);
                checkData.setWindDirection(excelValues[i][j++]);
                checkData.setWindSpeed(excelValues[i][j++]);
                list.add(checkData);
            }
            this.saveBatch(list);
            return true;
        }catch (Exception e){

        }
        return false;
    }
}
